<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%
	pageContext.setAttribute("APP_PATH", request.getContextPath());
%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="${APP_PATH}/js/jquery-1.11.1.min.js"></script>
<link href="${APP_PATH}/js/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- 可选的Bootstrap主题文件（一般不使用） -->
<script src="${APP_PATH}/js/bootstrap/css/bootstrap-theme.min.css"></script>
<link rel="stylesheet" type="text/css" href="${APP_PATH}/mycss/style.css" />
<link rel="stylesheet" href="${APP_PATH}/js/laypage/skin/laypage.css" media="all">
<script src="${APP_PATH}/js/laypage/laypage.js"></script>
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="${APP_PATH}/js/bootstrap/js/bootstrap.min.js"></script>
<title>Insert title here</title>
</head>
<body id="tablePage">
 <div>
		<blockquote>
			<p class="twoType">角色管理</p>
		</blockquote>
		<hr/>
	<div class="btnChange">
		<from class="form-horizontal" role="form" id="getConditionsFrom" method="post">
			<select style="width:80px;margin-left:-100;height:25px" onchange="A()" id="getCustomer" name="getCustomer">
				<option value="客户姓名">客户姓名</option>
				<option value="联系电话">联系电话</option>
			</select>
			<input class="btn-default" type="text" style="height:25px" id="getConditions" name="getConditions"/>
			<input class="btn-default" style="height:25px" type="button" id="getConditionsButton" value="查询" />
		</from>
		
	</div>
	<div class="btnChange">
		<input class="btn btn-default addBtn" type="button" value="添加" />
	</div>
	<div class="tableDiv">
		<form action="" >
			<table id="conTable" class="table table-bordered">
				<thead>
					<tr class="info"><td></td><td></td><td>客户姓名</td><td>性别</td><td>类型</td><td>状态</td><td>已消费次数</td><td>消费总额(单位:万元)</td><td>服务代表</td><td>操作</td></tr>
				</thead>					
				<tbody id="theFirstOneTable">
				</tbody>
				<tfoot><tr><td colspan="10"><div id="reviewfenye"></div></td></tr></tfoot>
			</table>
		</form>
	</div>
	
	<!--新增页面开始-->
	<div class="modal fade" id="addUser" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">新 增</h4>
				</div>
				 <form class="form-horizontal" role="form" id="addUserForm"
					 method="post" >
					<div class="modal-body">
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">输入姓名：
							</label>
							<div class=" form-group">
								<input type="text" class="form-control" name="cusName"
									id="cusName" style="width: 250px" maxlength="15"
									placeholder="请点击查询按钮"/>
							</div>
							<div class="col-sm-3 form-group" style="margin-left: 135px"> 
								<input type="button" class="btn btn-default" id="getClient" value="查询" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">性别：
							</label>
							<div class="col-sm-9">
								<input type="text" class=" sortNumber form-control"
									id="cusSex" id="address1" style="width: 250px" readonly="readonly"/>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">客户类型：
							</label>
							<div class="col-sm-9">
								<input type="text" class="form-control" id="cusRank"
									 style="width: 250px" readonly="readonly"/>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">客户状态：
							</label>
							<div class="col-sm-9">
								<input type="text" class=" sortNumber form-control"
									id="cusState" style="width: 250px" readonly="readonly" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">联系电话：
							</label>
							<div class="col-sm-9">
								<input type="text" class=" sortNumber form-control" id="cusHomePhone"
									 style="width: 250px" readonly="readonly" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">已消费次数：
							</label>
							<div class="col-sm-9">
								<input type="text" class=" sortNumber form-control" id="numberConsumption"
									 style="width: 250px" readonly="readonly" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">总消费金额：
							</label>
							<div class="col-sm-9">
								<input type="text" class=" sortNumber form-control" id="consumptionAmount"
								 style="width: 250px" readonly="readonly" />
							</div>
						</div>
						<div class="tableDiv form-group">
							<table  class="table table-bordered">
								<thead>
									<tr class="info"><th><input type="checkbox" name="checkAll" id="checkAll"/></th><th>商品编号</th><th>商品称号</th><th>型号</th><th>数量</th><th>单价(单位:元)</th><th>库存</th></tr>
								</thead>
								<tbody id="aaaaaaa">
								</tbody>
							</table>
						</div>
					</div>
					<div class="modal-footer">
						<input type="button" class="btn btn-primary" id="btnAddsubmit" value="下一步" />
						<!-- <button type="button" class="btn btn-default" data-dismiss="modal">关闭
						</button>; -->
					</div>
				 </form> 
				 </div>
				 </div>
			</div>
			<!-- /.modal-content -->
			<!--新增订单下一步-->
	<div class="modal fade" id="addUseraaa" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">填写并核对订单信息</h4>
				</div>
				 <form action="${APP_PATH}/orderManagement/theOrderOf/addOrder" class="form-horizontal" role="form" id="addOrderForm"
					 method="post"  enctype="multipart/form-data">
					<div class="modal-body">
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">收货人信息:
							</label>
							<div class=" form-group">
								<input type="hidden" class="form-control" id="userIdNext" name="cusId"
									 style="width: 250px" maxlength="15"
									placeholder="XXX"/>
								<input type="hidden" class="form-control" id="orTotalConsumptionAmount"
									name="orTotalConsumptionAmount" style="width: 250px" maxlength="15"
									placeholder="XXX"/>
								<input type="hidden" class="form-control" id="orSexNext"
									 name="orSex" style="width: 250px" maxlength="15"
									placeholder="XXX"/>
								<input type="hidden" class="form-control" id="orSuckersNext"
									name="orSuckers" style="width: 250px" maxlength="15"
									placeholder="XXX"/>
								<input type="hidden" class="form-control" id="orStateNext"
									name="orState" style="width: 250px" maxlength="15"
									placeholder="XXX"/>
								<input type="text" class="form-control" id="userNameNext"
									name="orName" style="width: 250px" maxlength="15"
									placeholder="XXX"/>
							</div>
							<div class=" form-group" style="margin-left: 135px">
								<input type="text" class="form-control" id="phoneNext"
									name="orPhone" style="width: 250px" maxlength="15"
									placeholder="XXX"/>
							</div>
							<div class=" form-group" style="margin-left: 140px">
								<input type="text" class="form-control" id="addressNext"
									name="orAddress" style="width: 250px" maxlength="15"
									placeholder="XXX"/>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">支付及配送信息:
							</label>
							<div class=" form-group" style="margin-left: 140px">
								<select style="width:118px;margin-left:-100;height:25px" onchange="A()" id="orModelPayment" name="orModelPayment">
							        <option  value="货到付款">货到付款</option>
							        <option value="先付款后送货">先付款后送货</option>
							        <option value="分期付款">分期付款</option>
						         </select>
						     </div>
						     <div class=" form-group" style="margin-left: 140px">
								  <select style="width:118px;margin-left:-100;height:25px" onchange="A()" id="orDeliveryMode" name="orDeliveryMode">
							        <option value="公司送货上门">公司送货上门</option>
							        <option value="客户上门取货">客户上门取货</option>
						          </select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">发票信息:
							</label>
							<div class=" form-group">
								<input type="file" class="form-control" name="orInvoiceInformationFile"
									id="orInvoiceInformation" style="width: 250px" maxlength="15"
									placeholder="公司明细"/>
							</div>
						</div>
						<div class="tableDiv form-group">
							<table  class="table table-bordered">
								<thead>
									<tr class="info"><th></th><th>商品称号</th><th>型号</th><th>单价(单位:元)</th><th>数量</th><th>库存</th></tr>
								</thead>
								<tbody id="bbbbb">
								</tbody>
							</table>
						</div>
					</div>
					<div class="modal-footer">
						<input type="submit"  class="btn btn-primary"  id="addOrdersubmit" value="提交订单" />
						<!-- <button  class="btn btn-primary"  id="addOrdersubmit">提交订单</button> -->
						<button  class="btn btn-default" data-dismiss="modal">关闭
						</button>
					</div>
				 </form> 
			</div>
			</div>
		</div>
			<!-- ----- -->
			<!--查看按钮 -->
	<div class="modal fade" id="queryCustomerOrderaaa" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">填写并核对订单信息</h4>
				</div>
				 <form action="" class="form-horizontal" role="form" id="queryCustomerOrderForm"
					 method="post"  enctype="multipart/form-data">
					<div class="modal-body">
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">收货人信息:
							</label>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">客户 姓名：
							</label>
							<div class="col-sm-9">
								<input type="text" class=" sortNumber form-control"
									id="getOrName" style="width: 250px" readonly="readonly" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">客户 性别：
							</label>
							<div class="col-sm-9">
								<input type="text" class=" sortNumber form-control"
									id="getOrSex" style="width: 250px" readonly="readonly" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">客户类型：
							</label>
							<div class="col-sm-9">
								<input type="text" class=" sortNumber form-control"
									id="getOrSuckers" style="width: 250px" readonly="readonly" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right">客户状态：
							</label>
							<div class="col-sm-9">
								<input type="text" class=" sortNumber form-control"
									id="getOrState" style="width: 250px" readonly="readonly" />
							</div>
						</div>
						
						<div class="tableDiv form-group" id="queryCustomerOrder">
							
						</div>
						
					</div>
					<div class="modal-footer">
						<button  class="btn btn-default" id="ShutDownViewPersonalInformation">关闭
						</button>
					</div>
				 </form> 
				</div>
				</div>
			</div>
			<!--  -->
</div>
<script type="text/javascript">
//条件查询时防止空指针写的默认值
var getCustomer="1";
var getConditions="2";

//查看按钮
function viewPersonalInformation(cusId){
	 cusId=parseInt(cusId);
	 $('#queryCustomerOrderaaa').modal('show');
	 $.ajax({
		url:"${APP_PATH}/orderManagement/theOrderOf/seeTheCustomer",
		type:"POST",
		data:{"cusId":cusId},
		dataType:"json",
		success:function(result){
			/* $("#queryCustomerOrderForm").html(""); */
			$("#getOrName").val(result.heyunOrder.orName);
			$("#getOrSex").val(result.heyunOrder.orSex);
			$("#getOrSuckers").val(result.heyunOrder.orSuckers);
			$("#getOrState").val(result.heyunOrder.orState);
			$.each(result.listOrCusId,function(i,item){
  				$("#queryCustomerOrder").append("<table class='table table-bordered'><thead class='table table-bordered'><tr class='active info'><td>订单编号:"+
  				item.orCusId+"</td><td>订单总金额:"+
  				item.orTotalConsunmptionAmount+"</td><td>支付方式:"+
  				item.orModelPayment+"</td><td>配送方式:"+
  				item.orDeliveryMode+"</td></tr><tr><td>收货地址:"+
  				item.orAddress+"</td><td>联系人电话:"+
  				item.orPhone+"</td><td>下单地址:"+
  				item.orDate+"</td></tr><tr><td><img src="+
  				item.orInvoiceInformation+" alt='订单明细'></td></tr><tr><td>商品名称</td><td>商品型号</td><td>商品单价</td><td>数量</td></tr></thead></table>");
  				console.log(result.listMerchandise);
  				$.each(result.listMerchandise,function(inx,items){
  					$.each(items,function(inx1,itemss){
  					$("#queryCustomerOrder").append("<table class='table table-bordered'><tr><td style='width:180px'>"+
  						itemss.orMerName+"</td><td style='width:220px'>"+
  						itemss.orMerModelNumber+"</td><td style='width:220px'>"+
  						itemss.orMerPrice+"</td><td style='width:180px'>"+
  						itemss.orNumber+"</td></tr></table>");
  						})
  					})	
				})
  				
			}
		})
	}
//查看的关闭按钮
$(document).delegate('#ShutDownViewPersonalInformation', 'click', function() {
	$("#queryCustomerOrderForm").html("");
	$('#addUser').modal('hide');
})

//条件查询 
$(document).delegate('#getConditionsButton', 'click', function() {
	var currentpage = 1;
	getCustomer = $("#getCustomer option:selected").val();
	getConditions = $("#getConditions").val();
	AutomaticLoading(getCustomer,getConditions,currentpage);
})
//from表单提交订单(添加订单)
$(document).delegate('#addOrdersubmit', 'click', function() {
	var cusId = $("#cusId").val();
	var orTotalConsumption = $("#orTotalConsumption").val();
	var orModelPayment = $("#orModelPayment").val();
	var orDeliveryMode = $("#orDeliveryMode").val();
	var orInvoiceInformation = $("#orInvoiceInformation").val();
	var orName = $("#orName").val();
	var orSex = $("#orSex").val();
	var orSuckers = $("orSuckers").val();
	var orState = $("#orState").val();
	var orAddress = $("#orAddress").val();
	var orPhone = $("#orPhone").val();
	var form = new FormData($("#addOrderForm")[0]);
	form.append("cusId",cusId);
	form.append("orTotalConsumption",orTotalConsumption);
	form.append("orModelPayment",orModelPayment);
	form.append("orDeliveryMode",orDeliveryMode);
	form.append("orInvoiceInformation",orInvoiceInformation);
	form.append("orName",orName);
	form.append("orSex",orSex);
	form.append("orSuckers",orSuckers);
	form.append("orState",orState);
	form.append("orAddress",orAddress);
	form.append("orPhone",orPhone);
	$.ajax({
		url:"${APP_PATH}/orderManagement/theOrderOf/addOrder",
		type:"POST",
		data:form,
		dataType:"json",
		success:function(data){
			
			}
		})
	})
//添加按钮中的下一步的操作(向购物车表添加信息)
$(document).delegate('#btnAddsubmit', 'click', function() {
	$('#addUser').modal('hide');
	$('#addUseraaa').modal('show');
	var cusId = document.getElementById("userIdNext").value;
	var orSex = document.getElementById("cusSex").value;
	$("#orSexNext").val(orSex);
	var orSuckers = document.getElementById("cusRank").value;
	$("#orSuckersNext").val(orSuckers);
	var orState = document.getElementById("cusState").value;
	$("#orStateNext").val(orState);
	var orPhone = document.getElementById("phoneNext").value;
	var orAddress = document.getElementById("addressNext").value;
		$.each($("#checkall:checked"),function(){
		merId = $(this).parents("tr").find("td:eq(1)").text();
		merName = $(this).parents("tr").find("td:eq(2)").text();
		merModelNumber = $(this).parents("tr").find("td:eq(3)").text();
		number = document.getElementById("goods"+merId).value;
		merPrice = $(this).parents("tr").find("td:eq(5)").text();
		merStock = $(this).parents("tr").find("td:eq(6)").text();
		$.ajax({
			type:"POST",
			url:"${APP_PATH}/orderManagement/theOrderOf/addShoppingCart",
			data:{"merId":merId, "merName":merName,"merModelNumber":merModelNumber,"number":number,"merPrice":merPrice,"merStock":merStock},
			dataType:"json",
			})
		})
		getShoppingCart(); 
})
//添加按钮中的下一步的操作(查询购物车表信息)
var getShoppingCart = function(){
	$.ajax({
		type:"POST",
		url:"${APP_PATH}/orderManagement/theOrderOf/getShoppingCart",
		data:"",
		dataType:"json",
		success:function(data){
			$("#listHeyunOrderMerchandise").val(data.listShoppingCart);
			$("#bbbbb").html("");
			$.each(data.listShoppingCart,function(i,item){
  				$("#bbbbb").append("<tr class='active' style='width:50px;'><td>"+ ++i+"</td><td>"+
  				item.shoMerName+"</td><td>"+
  				item.shoMerModelNumber+"</td><td>"+
  				item.shoMerPrice+"</td><td>"+
  				item.shoNumber+"</td><td>"+
  				item.shoMerStock+"</td></tr>");
  			})
  			$("#bbbbb").append("<div>总计:<span id='TotalConsumptionAmount'>"+data.toble+"</span>元</div>");
			$("#orTotalConsumptionAmount").val(data.toble*1);
			}
		});
	}
	

var aavalue1;
aavalue1 =parseInt(aavalue1);
//点击新增订单第一步
$(document).delegate('.addBtn', 'click', function() {
	aavalue1 = 1;
	aavalue1 = parseInt(aavalue1);
	$('#addUser').modal('show');
	$.ajax({
		type:"POST",
		url:"${APP_PATH}/orderManagement/theOrderOf/queryAllProducts",
		data:"",
		dataType:"json",
		success:function(data){
			$("#aaaaaaa").html("");
			$.each(data.listMerchandise,function(i,item){
  				$("#aaaaaaa").append("<tr class='active'><td><input type='checkbox' id='checkall' name='checkall'/></td><td style='width:50px;'>"+
  				item.merId+"</td><td>"+
  				item.merName+"</td><td>"+
  				item.merModelNumber+"</td><td><input type='button' onclick='subvalue("+
  				item.merId+")' value='-' /><input type='text' style='width:25px;' id='goods"+
  				item.merId+"' value='"+aavalue1+"'/ readonly='readonly'><input type='button' onclick='addvalue("+
  				item.merId+","+item.merStock+")' value='+' /></td><td>"+
  				item.merPrice+"</td><td>"+
  				item.merStock+"</td></tr>");
  			})
		}
	})
})
//添加按钮中的商品数量减的操作
var subvalue=function(del1){
	aavalue1 = document.getElementById("goods"+del1).value;
	aavalue1 =parseInt(aavalue1);
	if(aavalue1>0){
		aavalue1-=1;
		$("#goods"+del1).val(aavalue1);
	}else{
		aavalue1=0;
		$("#goods"+del1).val(aavalue1);
	}
}
//添加按钮中的商品数量加的操作
var addvalue=function(del2,stock){
	//var aavalue1 = $("#goods"+del1).val();
	aavalue1 = document.getElementById("goods"+del2).value;
	aavalue1 =parseInt(aavalue1);
	if(aavalue1<stock){
		aavalue1+=1;
		$("#goods"+del2).val(aavalue1);
	}else{
		aavalue1=stock;
		$("#goods"+del2).val(aavalue1);
	}
}
//添加功能中的点击查询按钮返回的值
$(document).delegate('#getClient', 'click', function() {
	var userName = $("#cusName").val();
	$.ajax({
		type:"POST",
		url:"${APP_PATH}/orderManagement/theOrderOf/orderOfService",
		data:{"userName":userName},
		dataType:"json",
		success:function(result){
			$("#cusName").val(result.HeYunCustomer.cusName); 
			$("#cusSex").val(result.HeYunCustomer.cusSex);
			$("#cusRank").val(result.HeYunCustomer.cusRank);
			$("#cusState").val(result.HeYunCustomer.cusState);
			$("#cusHomePhone").val(result.HeYunCustomer.cusHomePhone);
			$("#numberConsumption").val(result.totalQuantity);
			$("#consumptionAmount").val(result.totalAmount);
			//向下一页中添加客户信息
			$("#userIdNext").val(result.HeYunCustomer.cusId);
			$("#userNameNext").val(result.HeYunCustomer.cusName);
			$("#phoneNext").val(result.HeYunCustomer.cusHomePhone);
			$("#addressNext").val(result.HeYunCustomer.cusAddress);
		}
	})
})
$(document).ready(function() {
	var currentpage = 1;
	//点击全选改变
	$("#checkAll").click(function(){
		$("input[type='checkbox']").prop("checked",$(this).prop("checked"));
	})
	AutomaticLoading(getCustomer,getConditions,currentpage);
})
var AutomaticLoading = function(getCustomer,getConditions,currentpage){
	$.ajax({
		type:"POST",
		url:"${APP_PATH}/orderManagement/theOrderOf/AutomaticQuery",
		data:{"getCustomer":getCustomer,"getConditions":getConditions,"currentpage":currentpage},
		dataType:"json",
		success:function(result){
			$("#theFirstOneTable").html("");
			$.each(result.listHeyunOrderUser,function(i,item){
  				$("#theFirstOneTable").append("<tr class='active'><td>"+(i+1)+"</td><td><input type='checkbox' id='checkall' name='checkall'/></td><td>"+
  				item.orName+"</td><td>"+
  				item.orSex+"</td><td>"+
  				item.orSuckers+"</td><td>"+
  				item.orState+"</td><td>"+
  				item.totalConsumptionFrequency+"</td><td>"+
  				item.totalAmountPerUser+"</td><td>"+
  				item.empName+"</td><td><input type='button' id='lookBtn' class='btn btn-info btn-xs active'value='查看' onclick='viewPersonalInformation("+item.cusId+")'/></td></tr>");
  			})
  			laypage({
			 cont:'reviewfenye',//容器
		     pages:result.pages, //总页数
		     //limit:2,//每页显示的条数
		     curr:currentpage,//当前页
		     skin:'molv',//皮肤
		     skip:true,//
		     last:'尾页',//
		     jump:function(obj,first){
		    	 currentpage=obj.curr;
		    	     if(!first){
		    	    	 listByCondition(obj.curr);
		    	    	 }
		    	 }
			});
		}
	})
}

/* $(document).delegate3('.addBtn', 'click', function() {
	$('#addUser').modal('show');
	//$("body").css("padding-right",0);
}); */
	</script>
</body>
</html>